View Javadoc
1 package com.fc.taglibs.castor; 2 3 import java.io.*; 4 import java.util.ArrayList; 5 import javax.naming.*; 6 import javax.servlet.jsp.*; 7 import javax.servlet.jsp.tagext.*; 8 import org.apache.taglibs.standard.lang.support.*; 9 10 import org.exolab.castor.jdo.DataObjects; 11 import org.exolab.castor.jdo.Database; 12 import org.exolab.castor.jdo.ClassNotPersistenceCapableException; 13 import org.exolab.castor.jdo.TransactionNotInProgressException; 14 import org.exolab.castor.jdo.PersistenceException; 15 16 public class CastorDeleteTag extends BodyTagSupport 17 { 18 19 /*** 20 * The name of this tag 21 */ 22 private static String _tagName = "CastorDeleteTag"; 23 24 /*** 25 * The object to update 26 */ 27 private Object data; 28 29 /*** 30 * The database to perform the update 31 */ 32 private Database db = null; 33 34 35 /*** 36 * The name of the data object 37 * to be retrieved from page scope 38 */ 39 private String name = null; 40 41 42 /*** 43 * Sets the name of the page scoped attribute 44 * that is the bean we are deleting/updating 45 */ 46 public void setName(String _name) 47 { 48 this.name = _name; 49 } 50 51 /*** 52 * Do the start tag bit 53 */ 54 public int doStartTag() throws JspException 55 { 56 57 try 58 { 59 /* 60 * Get the data object 61 */ 62 if (pageContext.getAttribute(this.name,PageContext.PAGE_SCOPE)!=null) 63 data = pageContext.getAttribute(this.name,PageContext.PAGE_SCOPE); 64 else if (pageContext.getAttribute(this.name,PageContext.REQUEST_SCOPE)!=null) 65 data = pageContext.getAttribute(this.name,PageContext.REQUEST_SCOPE); 66 else if (pageContext.getAttribute(this.name,PageContext.SESSION_SCOPE)!=null) 67 data = pageContext.getAttribute(this.name,PageContext.SESSION_SCOPE); 68 else if (pageContext.getAttribute(this.name,PageContext.APPLICATION_SCOPE)!=null) 69 data = pageContext.getAttribute(this.name,PageContext.APPLICATION_SCOPE); 70 else 71 { 72 String msg = "Data object " + this.name + " could not be found in any scope."; 73 log(msg,null); 74 throw new Exception(msg); 75 } 76 77 /* 78 * Check to see if this tag is nested within a transactional tag 79 * Get the transaction. Exception if no Transaction parent tag found. 80 */ 81 CastorTransactionInitiator t = (CastorTransactionInitiator)findAncestorWithClass(this, CastorTransactionInitiator.class); 82 if (t!=null) 83 { 84 db = t.getDatabase(); 85 log ("Got transaction from parent tag", null); 86 log ("Removing data: " + data,null); 87 db.remove(data); 88 } 89 else 90 { 91 String msg = "Tag not nested within a CastorTransactionTag."; 92 log(msg,null); 93 throw new Exception(msg); 94 } 95 } 96 catch(ClassNotPersistenceCapableException e) 97 { 98 log(e.getMessage() , e); 99 throw new JspTagException(e.getMessage()); 100 } 101 catch(TransactionNotInProgressException e) 102 { 103 log(e.getMessage() , e); 104 throw new JspTagException(e.getMessage()); 105 } 106 catch(PersistenceException e) 107 { 108 log(e.getMessage() , e); 109 throw new JspTagException(e.getMessage()); 110 } 111 catch(Exception e) 112 { 113 log(e.getMessage() , e); 114 throw new JspTagException(e.getMessage()); 115 } 116 117 return EVAL_PAGE; 118 } 119 120 private void log(String msg,Exception e) 121 { 122 if (e!=null) 123 { 124 System.err.println(_tagName + ": " + msg); 125 e.printStackTrace(); 126 } 127 else 128 { 129 System.out.println(_tagName + ": " + msg); 130 } 131 } 132 133 }

This page was automatically generated by Maven